/**
 * 
 */
package com.fengniu.ejb.dao.util;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Query;

/**
 * @author Conan
 * 
 */
public class DaoUtil {
	public static boolean isNull(Object[] objects) {
		if (objects != null)
			for (Object o : objects) {
				if (o != null)
					return false;
			}
		return true;
	}

	public static List getResultList(Query q, int pgno, int pgsize) {
		List result = (pgno >= 0 && pgsize > 0) ? q.setFirstResult(pgno * pgsize).setMaxResults(pgsize).getResultList()
				: q.getResultList();
		return result;
	}

	public static String getWhereOrAndStr(String whereand) {
		String result = "";
		if (whereand == null || whereand.trim().equals("")) {
			result = " where ";
		} else {
			result = " and ";
		}
		return result;
	}

	public static List<Object> getListFromArray(Object[] arrayObjs) {
		ArrayList<Object> rts = new ArrayList<Object>(0);
		for (int i = 0; i < arrayObjs.length; i++) {
			if (arrayObjs[i] != null) {
				rts.add(arrayObjs[i]);
			}
		}
		if (rts.size() == 0)
			return null;
		return rts;
	}

	public static List<Object> getListFromArray(long[] arrayObjs) {
		ArrayList<Object> rts = new ArrayList<Object>(0);
		if (arrayObjs != null) {
			for (int i = 0; i < arrayObjs.length; i++) {
				rts.add(new Long(arrayObjs[i]));
			}
		}
		if (rts.size() == 0)
			return null;
		return rts;
	}
}
